<?php
class menu_model extends CI_Model{
	function menu_model(){  
         parent::__construct();  
         $this->load->helper('url');                 
  	}  
	function getMenu($menuType,$webStore){
		$this->load->database();
		$result = null;
		  
   		$this->db->select('id,link,name,parent as pr');
	    $this->db->Where('menutype',$menuType);
	    $this->db->Where('published',1);
	    if($webStore!=''){
	    	$this->db->Where('webstore',$webStore);	
	    }
	    $this->db->order_by('parent,ordering');
	    $query = $this->db->get('menu');
	    
	    if(!empty($query)){
	    	$result = $query->result();
	    }
	    return $result;	
	}
	function getTemplateForUrl(){
		$url='';
		$template="";
		$subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2); 
		$subdomain_name='';
		 if(count($subdomain_arr)>0){
		 	for($i=0;$i<=count($subdomain_arr)-1;$i++){
		 		$subdomain_name.= $subdomain_arr[$i].'.';
		 	}
		 	$subdomain_name=substr($subdomain_name,0,-1);
		 }
        $domain=$this->config->item('domain');
        $linktype='subdomain';
        if($subdomain_name!='' && $domain!=$subdomain_name){
        	$url=$subdomain_name;
        }else{
        	$linktype='subfolder';
        	$url=$this->uri->segment(1).'/'.$this->uri->segment(2);
        } 
		$this->load->database();  
   		$query = $this->db->getwhere('webstore',"webstorelink ='$url' ");  
   		$webstoreObj= $query->row_array();
		return $webstoreObj;
	}
}